package org.gjy.m8.concurrent;

import com.alibaba.ttl.TransmittableThreadLocal;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author gjy
 * @version 1.0
 * @since 2025-07-08 12:18:45
 */
public class ThreadLocalTest {
    private static final Logger log = LoggerFactory.getLogger(ThreadLocalTest.class);

    public static void main(String[] args) throws InterruptedException {
        TransmittableThreadLocal<String> ttl = new TransmittableThreadLocal<>();
        ThreadPoolExecutor pool = ThreadPoolUtil.getDefaultPool();
        ttl.set("Hello World");
        pool.submit(() -> {
            System.out.println(ttl.get());
        });
        pool.shutdown();

    }

    private static void extracted() {
        ThreadLocal<String> tl = new ThreadLocal<>();
        tl.set("hello");

        InheritableThreadLocal<String> itl = new InheritableThreadLocal<>();

        ThreadPoolExecutor pool = ThreadPoolUtil.getDefaultPool();
        /*for (int i = 0; i < 5; i++) {
            pool.submit(() -> {
                String s = itl.get();
                log.info("s: {}", s);
            });
        }*/
        pool.submit(() -> {
            itl.set("Hello World");
        });
        pool.submit(() -> log.info("a: {}", itl.get()));
        pool.shutdown();
        log.info("main: {}", itl.get());
    }

}
